/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function (nums) {
  nums.sort((a, b) => a - b)
  let left = 1, len = nums.length,count=1
  while (left < len) {
    if(nums[left]==nums[left-1]){
      count++
      if(count>Math.floor(len/2)){
        return nums[left]
      }
    }else{
      count=1
    }
    left++
  }
};